
#if DDD
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using Firebase;
using Firebase.Analytics;
using UnityEngine;
/// <summary>
/// Firebase.Analytics代理，对应SDK平台的分析业务
/// </summary>
public class FirebaseAnalyticsAgent {
    static FirebaseAnalyticsAgent instance;
    public static FirebaseAnalyticsAgent GetInstance {
        get {
            if (instance == null) {
                instance = new FirebaseAnalyticsAgent();
            }
            return instance;
        }
    }
    bool isCanUse;
    public void Init(string userId) {
        if (C_Parameter.isUse == false) {
            Debug.LogWarningFormat("Firebase_____未开启");
            return;
        }
        Debug.Log("fireBase.Analytics  开始 初始化--");
        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available) {
                isCanUse = true;
                FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
                FirebaseAnalytics.SetUserId(userId);
                Debug.Log("fireBase.Analytics  初始化完成---");
            } else {
                isCanUse = false;
                Debug.LogErrorFormat("fireBase.Analytics  初始化失败==Could not resolve all Firebase dependencies: {0}", dependencyStatus);
            }
        });
    }
    public bool isInitComplete {

        get {
            if (C_Parameter.isUse == false) {
                Debug.LogWarningFormat("Firebase_____未开启");
                return false;
            }
            return isCanUse;
        }
    }
    /// <summary>
    /// 用户属性设置
    /// </summary>
    public void SetUserProperty(string userPropertyName, string propertyValue) {
        if (C_Parameter.isUse == false) {
            Debug.LogWarningFormat("Firebase_____未开启");
            return;
        }
        if (isCanUse == false) {
            Debug.Log("FirebaseAnalyticsAgent.SetUserProperty()--不能使用");
            return;
        }
        try {
            //Debug.LogFormat("FirebaseAnalyticsAgent.SetUserProperty()----{0}---{1}-",userPropertyName, propertyValue);
            FirebaseAnalytics.SetUserProperty(userPropertyName, propertyValue);
        } catch (Exception ex) {
            Debug.LogError(ex.Message);
        }
    }
    /// <summary>
    /// 设置事件
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="parameters">参数列表</param>
    public void SetEvent(string eventName, Parameter[] parameters) {
        if (C_Parameter.isUse == false) {
            Debug.LogWarningFormat("Firebase_____未开启");
            return;
        }
        if (isCanUse == false) {
            Debug.Log("FirebaseAnalyticsAgent.SetEvent()--不能使用");
            return;
        }
        try {
            //Debug.LogFormat("FirebaseAnalyticsAgent.SetEvent()--发送消息_{0}__{1}", eventName, parameters.Length);
            FirebaseAnalytics.LogEvent(eventName, parameters);
        } catch (Exception ex) {
            Debug.LogError(ex.Message);
        }
    }
    /// <summary>
    /// 设置事件
    /// </summary>
    /// <param name="eventName">事件名</param>
    /// <param name="eventParameterDic">事件参数名称和参数值集合--key==参数名,value==参数值</param>
    public void SetEvent(string eventName, Dictionary<string, string> eventParameterDic) {
        if (C_Parameter.isUse == false) {
            Debug.LogWarningFormat("Firebase_____未开启");
            return;
        }
        if (isCanUse == false) {
            return;
        }
        Parameter[] parameters = new Parameter[eventParameterDic.Count];
        int i = 0;
        string ss = eventName + "--> ";
        foreach (var n in eventParameterDic) {
            parameters[i] = new Parameter(n.Key, n.Value);
            i++;
            ss += n.Key + "=" + n.Value + "___";
        }
        Debug.Log(ss);
        try {
            FirebaseAnalytics.LogEvent(eventName, parameters);
        } catch (Exception ex) {
            Debug.LogError(ex.Message);
        }
    }
    [Obsolete("这个方法过时了 '兄弟'  请使用SetEvent方法")]
    /// <summary>
    /// 记录没有参数的事件。
    /// </summary>
    public void Login(int playerLevel) {
        if (C_Parameter.isUse == false) {
            Debug.LogWarningFormat("Firebase_____未开启");
            return;
        }
        if (isCanUse == false) {
            return;
        }
        //Debug.Log("登录事件。==Logging a login event.");

        //FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventLogin);
        //FirebaseAnalytics.SetUserProperty(FirebaseAnalytics.ParameterLevel, "" + playerLevel);
    }
    [Obsolete("这个方法过时了 '兄弟'  请使用SetEvent方法")]
    /// <summary>
    /// 玩家升级
    /// </summary>
    /// <param name="playerLevel">玩家等级</param>
    /// <param name="flightNumber">累计起飞次数</param>
    /// <param name="hitNumber">累计碰到障碍物结束次数</param>
    /// <param name="normalLandingNumber">累计正常降落结束次数</param>
    /// <param name="playRewradVideoNumber">累计播放激励广告次数</param>
    /// <param name="playForceAdsNumber">累计播放强制广告次数</param>
    /// <param name="gameTotalTime">累计游戏时长</param>
    public void LevelUp(int playerLevel, int flightNumber, int hitNumber, int normalLandingNumber, int playRewradVideoNumber, int playForceAdsNumber, int gameTotalTime) {
        if (C_Parameter.isUse == false) {
            Debug.LogWarningFormat("Firebase_____未开启");
            return;
        }
        if (isCanUse == false) {
            return;
        }
        //Debug.Log("升级事件。== Logging a level up event.");
        //try {
        //    FirebaseAnalytics.LogEvent(
        //        FirebaseAnalytics.EventLevelUp,
        //        new Parameter(FirebaseAnalytics.ParameterLevel, playerLevel),//玩家等级
        //        new Parameter("flightNumber", flightNumber),//累计起飞次数
        //        new Parameter("hitNumber", hitNumber),//累计碰到障碍物结束次数
        //        new Parameter("normalLandingNumber", normalLandingNumber),//累计正常降落结束次数
        //        new Parameter("playRewradVideoNumber", playRewradVideoNumber),//累计播放激励广告次数
        //        new Parameter("playForceAdsNumber", playForceAdsNumber),//累计播放强制广告次数
        //        new Parameter("gameTotalTime", gameTotalTime)//累计游戏时长
        //        );
        //} catch (Exception ex) {
        //    Debug.LogError(ex.Message);
        //}
    }
    [Obsolete("这个方法过时了 '兄弟'  请使用SetEvent方法")]
    /// <summary>
    /// 飞行结束后领取奖励
    /// </summary>
    /// <param name="playerLevel">玩家等级</param>
    /// <param name="flightNumber">累计起飞次数</param>
    /// <param name="hitNumber">累计碰到障碍物结束次数</param>
    /// <param name="normalLandingNumber">累计正常降落结束次数</param>
    /// <param name="playForceAdsNumber">累计播放强制广告次数</param>
    /// <param name="gameTotalTime">累计游戏时长</param>
    public void FlightEndReceiveReward(int playerLevel, int flightNumber, int hitNumber, int normalLandingNumber, int playForceAdsNumber, int gameTotalTime) {
        if (C_Parameter.isUse == false) {
            Debug.LogWarningFormat("Firebase_____未开启");
            return;
        }
        if (isCanUse == false) {
            return;
        }
        //Debug.Log("飞行结束后领取奖励。=----------------------");
        //try { 
        //FirebaseAnalytics.LogEvent(
        //    "flightEndReceiveReward",
        //    new Parameter("level", playerLevel),//玩家等级
        //    new Parameter("flightNumber", flightNumber),//累计起飞次数
        //    new Parameter("hitNumber", hitNumber),//累计碰到障碍物结束次数
        //    new Parameter("normalLandingNumber", normalLandingNumber),//累计正常降落结束次数
        //    new Parameter("playForceAdsNumber", playForceAdsNumber),//累计播放强制广告次数
        //    new Parameter("gameTotalTime", gameTotalTime)//累计游戏时长
        //    );
        //} catch (Exception ex) {
        //    Debug.LogError(ex.Message);
        //}
    }
    [Obsolete("这个方法过时了 '兄弟'  请使用SetEvent方法")]
    /// <summary>
    /// 升级技能
    /// </summary>
    /// <param name="playRewardAdsNumber">累计播放激励广告次数</param>
    /// <param name="flightSpeedSkillLevel">飞行速度技能等级</param>
    /// <param name="upHighSkillLevel">爬升高度技能等级</param>
    /// <param name="offlineReward">离线收益技能等级</param>

    public void UpgradeSkill(int playRewardAdsNumber, int flightSpeedSkillLevel, int upHighSkillLevel, int offlineReward) {
        if (C_Parameter.isUse == false) {
            Debug.LogWarningFormat("Firebase_____未开启");
            return;
        }
        if (isCanUse == false) {
            return;
        }
        //Debug.Log("升级技能----------------------");
        //try {
        //    FirebaseAnalytics.LogEvent(
        //        "upgradeSkill",
        //        new Parameter("playRewardAdsNumber", playRewardAdsNumber),//累计播放激励广告次数
        //        new Parameter("flightSpeedSkillLevel", flightSpeedSkillLevel),//飞行速度技能等级
        //        new Parameter("upHighSkillLevel", upHighSkillLevel),//爬升高度技能等级
        //        new Parameter("offlineReward", offlineReward)//离线收益技能等级
        //        );
        //} catch (Exception ex){
        //    Debug.LogError(ex.Message);
        //}
    }
    public class C_Parameter {
        public static bool isUse = false;
    }
}


#endif
